﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace System.Qizx.XQuery.Op {
    class ExitExpr : Expression {
        Expression result;

        public ExitExpr(Expression ret) {
            result = ret;
        }

        public override Expression Child(int rank) {
            return rank == 0 ? result : null;
        }

        public override Expression StaticCheck(ModuleContext context, int flags) {
            result = context.staticCheck(result, 0);
            setType(result.getType());
            return this;
        }

        public override XQValue eval(Focus focus, EvalContext context) {
            XQValue res = result.eval(focus, context);
            throw new ExitException(res);
        }

    }
}